
//----------- 实现原理

let regeneratorRuntime = {
    mark(genFn) {
        return genFn
    },
    wrap(iteratorFn) {
        const context = {
            next: 0,
            done: false, // 迭代器是否执行结束
            stop() {
                context.done = true // 整个函数是否执行完成
            },
            sent: null // next参数 用户赋值给上一个yield的返回值
        }
        let it = {}
        it.next = function (value) { // 返回给上一个yield的返回值
            context.sent = value
            let v = iteratorFn(context)
            return {
                value: v,
                done: context.done
            }
        }
        return it
    }
}

//-----babeljs.io 编译结果

var _marked = /*#__PURE__*/regeneratorRuntime.mark(read);

function read() {
    var a, b, c;
    return regeneratorRuntime.wrap(function (_context) {
        while (1) {
            switch (_context.prev = _context.next) {
                case 0:
                    _context.next = 2;
                    return 1;

                case 2:
                    a = _context.sent;
                    console.log(a);
                    _context.next = 6;
                    return 2;

                case 6:
                    b = _context.sent;
                    console.log(b);
                    _context.next = 10;
                    return 3;

                case 10:
                    c = _context.sent;
                    console.log(c);

                case 12:
                case "end":
                    return _context.stop();
            }
        }
    }, _marked);
}



let r = read()
r.next()
r.next('a')
r.next('b')
r.next('c')